package labox.innovation.gameserver.network.serverpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.config.Config;
import labox.innovation.gameserver.model.L2ItemInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.clientpackets.RequestForgeItem;
import labox.innovation.gameserver.templates.item.ItemCompositeConfig;
import labox.innovation.gameserver.templates.item.ItemStarConfig;
import labox.innovation.gameserver.templates.item.ItemCompositeConfig.ItemCompositeData;
import labox.innovation.gameserver.templates.item.ItemStarConfig.ItemStarData;

/**
 * ֪ͨ�ͻ��� ����ɹ�
 * ���Ҹ��� ���� ��Ҫ��Ǯ �� ����
 * @author zjj
 *
 */
public class ForgeItemSucess extends L2GameServerPacket {

	private static final String ForgeItemSucess = "[S] 0x7c ForgeItemSucess";

	protected static final Logger _log = LoggerFactory.getLogger(ForgeItemSucess.class.getName());
	
	private final L2ItemInstance _item;

	private int _moneyType; //Ǯ������   0:���� 1:��Ʊ 2:Ԫ��

	private int _needMoney; //��Ҫ�� Ǯ

	private int _chance; //����

	private int _silverNums; //��ɫ���ϵ� ������

	private int _noteNums; //��Ʊ����

	private int _yuanbaoNums; //Ԫ������

	private int _flag;

	private int _sucess; //ʧ�ܻ�ɹ�   0��ʧ�ܣ� 1���ɹ�

	public ForgeItemSucess(FuzePcInstance player, L2ItemInstance item, int flag, int sucess) {
		_item = item;
		_flag = flag;
		_sucess = sucess;
		if (item != null) {
			if (flag == RequestForgeItem.OP_START) {
				ItemStarData starData = ItemStarConfig.getInstance().getItemStarData(item.getItemTypeString(), item.getItemLvl(), item.getStarLvl());
				if( starData != null ){
					_needMoney = starData._moneySilverNums;
					_chance = starData._upchance;
					_moneyType = starData._moneyType;
				}else
				{
					_log.warn("׷��������ݲ����� :" +item.getItemTypeString() +  " ��Ʒ�ȼ�: " + item.getItemLvl() + " ׷�ǵȼ�:" + item.getStarLvl(), Config.SERVER_ID);
				}

			} else if (flag == RequestForgeItem.OP_COMPOSITIE) {
				ItemCompositeData compositeData = ItemCompositeConfig.getInstance().getItemCompositeData(item.getItemGrade(), item.getItemLvl());
				if( compositeData != null ){
					_needMoney = compositeData._moneySilverNums;
					_chance = compositeData._chance;
					_moneyType = compositeData._moneyType;
				}else
				{
					_log.warn("�ϳ�������ݲ�����:" + "��ƷƷ��:" + item.getItemGrade() + "��Ʒ�ȼ�:" + item.getItemLvl() , Config.SERVER_ID);
				}

			}
		}

		if (player != null) {
			_silverNums = player.getMoneySilver();
			_noteNums = player.getMoneyNote();
			_yuanbaoNums = player.getMoneyYuanBao();
		}

	}

	@Override
	public String getType() {

		return ForgeItemSucess;
	}

	@Override
	protected void writeImpl() {

		writeByte(PTL_FORGEITEMSUCESS);
		writeByte(_flag);
		writeByte(_sucess);
		writeByte(_moneyType);
		writeInt(_needMoney);
		writeByte(_chance / 100);
		writeInt(_silverNums);
		writeInt(_noteNums);
		writeInt(_yuanbaoNums);

	}

}
